
matlabSkeleton= """    
function f = mscript() 
%path(P,'/user/home/John')
P=path
path(P,'N:\\BBSRC 2009-12 Measuring Microscope\\NEUROMORPH\\tools\')

% Please save all your original swc, which you would like to straithen, to
% some directory with name dir_name1
dir_name1='N:\BBSRC 2009-12 Measuring Microscope\NEUROMORPH\swc raw\aIN 471';
dir_name1='__INDIR__';
file_name=
%Please prepare an empty directory were you woulke to the get new files with
%converted coordinates. Names of these files in a new directory will be the
%same but with added s at the end of the name: '...s.swc'.
%The name of this empty directory is dir_name2:
dir_name2='N:\BBSRC 2009-12 Measuring Microscope\NEUROMORPH\swc transformed\aIN 471';
dir_name2='__OUTDIR__';

file_name='__FILENAME__'
%To convert all files use the following comand:
n_files=convert_all_n(dir_name1,dir_name2,file_name)
% Note that if there are no the ventral edge, then the file will 
%be not converted. In this case the code with display a message and 
%the new file willl be almost empty (will contain only lines with 
%initial information).
% The variable n_files shows how many files have been converted.
%

%ADD TO PATH:
%N:\BBSRC 2009-12 Measuring Microscope\NEUROMORPH\tools

exit
end

"""



import os
from util import ReadFile, WriteFile

def nrnStraighten(srcFilename, sinkFilename, matlabscriptname):
    #matlabScriptName
    
    
    srcDir = os.path.dirname(srcFilename)
    romanOutDir = os.path.join( srcDir, "Roman_out" )
    if not os.path.exists(romanOutDir): os.makedirs(romanOutDir)
    
    mlabdata = matlabSkeleton.replace( "__INDIR__", srcDir). replace("__OUTDIR__", romanOutDir) .replace("__FILENAME__", srcFilename)
    WriteFile( matlabscriptname, mlabdata)
    
    INDIR = os.path.dirname(srcFilename)
    OUTDIR = os.path.dirname

    os.chdir(srcDir)
    #execCmd = """cd "%s" && matlab -nosplash -r mscript -logfile c:\temp\logfile"""%srcDir.replace("/","\\")
    #print execCmd
    #os.system(execCmd)
    
    #opfilename = os.path.join( romanOutDir, os.path.split(srcFilename)[1].replace(".swc","s.swc") )
    #assert os.path.exists(opfilename)
    
    #This is the original
    #WriteFile(sinkFilename, ReadFile(opFilename) )
    WriteFile(sinkFilename, ReadFile(srcFilename) ) 




"""    
% Please save all your original swc, which you would like to straithen, to
% some directory with name dir_name1
dir_name1='N:\BBSRC 2009-12 Measuring Microscope\NEUROMORPH\swc raw\aIN 471';
%Please prepare an empty directory were you woulke to the get new files with
%converted coordinates. Names of these files in a new directory will be the
%same but with added s at the end of the name: '...s.swc'.
%The name of this empty directory is dir_name2:
dir_name2='N:\BBSRC 2009-12 Measuring Microscope\NEUROMORPH\swc transformed\aIN 471';
%To convert all files use the following comand:
n_files=convert_all_n(dir_name1,dir_name2)
% Note that if there are no the ventral edge, then the file will 
%be not converted. In this case the code with display a message and 
%the new file willl be almost empty (will contain only lines with 
%initial information).
% The variable n_files shows how many files have been converted.
%

%ADD TO PATH:
%N:\BBSRC 2009-12 Measuring Microscope\NEUROMORPH\tools
"""